home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / sokoban-.tar / sokoban-src.tar / sokoban / readscreen.c < prev    next >
C/C++ Source or Header  |  1990-10-09  |  1KB  |  58 lines

  1. #include <stdio.h>
  2. #include "sokoban.h"
  3.  
  4. extern char *malloc();
  5. extern FILE *fopen();
  6.  
  7. extern short level, packets, savepack, rows, cols;
  8. extern char  map[MAXROW+1][MAXCOL+1];
  9. extern POS   ppos;
  10.  
  11. short readscreen() {
  12.  
  13.    FILE *screen;
  14.    char *fnam;
  15.    short j, c, ret = 0;
  16.  
  17.    fnam = malloc( strlen( SCREENPATH) + 11);
  18.    sprintf( fnam, "%s/screen.%d", SCREENPATH, level);
  19.    if( (screen = fopen( fnam, "r")) == NULL) 
  20.       ret = E_FOPENSCREEN;
  21.    else {
  22.       packets = savepack = rows = j = cols  = 0;
  23.       ppos.x = -1; ppos.y = -1;
  24.       while( (ret == 0) && ((c = getc( screen)) != EOF)) {
  25.          if( c == '\n') {
  26.         map[rows++][j] = '\0';
  27.         if( rows > MAXROW) 
  28.            ret = E_TOMUCHROWS;
  29.         else {
  30.            if( j > cols) cols = j;
  31.            j = 0;
  32.         }
  33.      }
  34.      else if( (c == player.obj_intern) || (c == playerstore.obj_intern)) {
  35.         if( ppos.x != -1) 
  36.            ret = E_PLAYPOS1;
  37.         else { 
  38.            ppos.x = rows; ppos.y = j;
  39.            map[rows][j++] = c;
  40.            if( j > MAXCOL) ret = E_TOMUCHCOLS;
  41.         }
  42.      }
  43.      else if( (c == save.obj_intern) || (c == packet.obj_intern) ||
  44.           (c == wall.obj_intern) || (c == store.obj_intern) ||
  45.           (c == ground.obj_intern)) {
  46.         if( c == save.obj_intern)   { savepack++; packets++; }
  47.         if( c == packet.obj_intern) packets++;
  48.         map[rows][j++] = c;
  49.         if( j > MAXCOL) ret = E_TOMUCHCOLS;
  50.      }
  51.      else ret = E_ILLCHAR;
  52.       }
  53.       fclose( screen);
  54.       if( (ret == 0) && (ppos.x == -1)) ret = E_PLAYPOS2;
  55.    }
  56.    return( ret);
  57. }
  58.